<template>
  <img :src="imageUrl" :alt="alt" @click="$emit('click')" />
</template>

<script>
import request from '@/utils/request.js' 

export default {
  name: "BCTokenImage",
  props: {
    src: String,
    alt: String
  },
  data() {
    return {
      imageUrl: "", // 可以默认给一个占位图片
    };
  },
  watch: {
    src: {
      handler(value) {
        this.loadImage(value);
      },
      immediate: true,
    }
  },
  methods: {
    loadImage(url) {
	  let token = uni.getStorageSync('userToken');
      let headers = { 
      	"token": token   // 签名（看具体需要）
      };
	  console.log(url);
	  
	  uni.downloadFile({
		  url: `/b/imgpath`+"/"+url, // 线上
		  //url: `/imgpath`+"/"+url,   //本地不需要加 前缀 /b
		  header: headers,
		  success: (data) => {
		  	console.log(data.tempFilePath);
		   this.imageUrl = data.tempFilePath;
		  }
	  })
	  
	  
	 /* uni.request({
		url: url,
		header: headers,
		method: 'GET',
		 success: (response) => {
			 this.imageUrl = URL.createObjectURL(new Blob([response]));
		 },
	  }) */
	
    }
  }
};
</script>
